package com.neusoft.a132wxyorderingdish.fragments;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.neusoft.a132wxyorderingdish.R;
import com.neusoft.a132wxyorderingdish.adapter.ShopAdapter;
import com.neusoft.a132wxyorderingdish.beans.ShopBean;
import com.neusoft.a132wxyorderingdish.listener.RetrofitListener;
import com.neusoft.a132wxyorderingdish.model.ShopModel;

import java.util.List;

public class ShopFragment extends BaseFragment implements RetrofitListener<List<ShopBean>> {
    private RecyclerView recyclerView;
    private ShopAdapter adapter;
    private String userid;


    @Override
    void initView() {

    }

    @Override
    void initEvent() {

    }

    @Override
    void initData() {

    }

    public ShopFragment() {
        // Required empty public constructor
    }
    @SuppressLint("ValidFragment")
    public ShopFragment(String userid){
        this.userid=userid;
    }
    //获取布局对象
    @Override
    public void onViewCreated(@NonNull View view, @NonNull Bundle savedInstanceState){
        super.onViewCreated(view, savedInstanceState);
        //对应布局
        recyclerView=view.findViewById(R.id.shop_list);

        if(getActivity()!=null){
            LinearLayoutManager layoutManager=new LinearLayoutManager(getActivity());
            //设置垂直布局
            layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            //设置布局管理器
            recyclerView.setLayoutManager(layoutManager);


            //请求数据
            ShopModel shopModel=new ShopModel();
            shopModel.getAllShops(this);
        }
    }

    @Override
    public void onSuccess(List<ShopBean> shops, int flag) {
        adapter=new ShopAdapter(getActivity(),shops);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onFail() {

    }

    //回调方法
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_shop, container, false);
    }

}
